package com.jmemoir.base.common.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * 自定义过滤器
 *
 * @author Tellsea
 * @date 2023/8/2
 */
@Slf4j
@Component
public class CustomFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("【自定义过滤器】初始化时调用...");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info("【自定义过滤器】实际处理过滤...");
        // 调用chain.doFilter方法将请求传递给下一个过滤器或目标资源
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        log.info("【自定义过滤器】销毁时调用...");
    }
}